<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page 
  language="java"
  contentType="text/html; charset=ISO-8859-1"
  import="com.epro.standard.frontend.util.FileInfoUtil,
                com.epro.standard.frontend.util.EproServletUtil,
                java.util.Vector,
                java.util.Date,               
                java.text.SimpleDateFormat,
                java.util.Locale,
                java.text.ParseException,
                com.softplus.carrefour.hd.bltier.entity.*,
                com.epro.standard.frontend.util.ShowData,
                com.softplus.carrefour.hd.bltier.util.DateUtil,
                com.softplus.carrefour.hd.bltier.admin.CountryManage,
                com.softplus.carrefour.hd.bltier.report.CCaseReportManage"
%>
<%
        //Current Date
        Date d = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.US);
             
        
        String user =  request.getParameter("uid");      
        DateUtil dateU = new DateUtil();
        System.out.println("====================User ID===================" + user);
        String currentDate = formatter.format(dateU.getLocalDate(user)); 
        System.out.println("====================Current Date===================" + currentDate);
        
        String backURL		= "CFHDRPMT04.jsp?uid=" + user;
        String backClick		= "location='" + backURL + "'" ; 
        
        //---Column Width Total = 735
        String width1 = "120";
        String width2 = "290";
        String width3 = "80";
        String width4 = "55";
        String width5 = "135";
        String width6 = "30";
        String width7 = "25";
        
        //---Header Width Total = 735
        String widthH1 = "185";
        String widthH2 = "210";
        String widthH3 = "55";
        String widthH4 = "75";
        String widthH5 = "65";
        String widthH6 = "55";
        String widthH7 = "30";      
                
        //---Result Table Width
        String ResultWidth = "750";
        //Main Table Width
        String MainWidth = "750";
        
        //========= Variable of System=========
  	ShowData showData 	= new ShowData();
%>
<HTML xmlns:epro>
<%@  taglib uri="/WEB-INF/HeadTag.tld" prefix="head"%>  
<%@  taglib uri="/WEB-INF/TextfieldTag.tld" prefix="textfield"%>
<%@ taglib uri="/WEB-INF/CalendarTag.tld" prefix="calendar"%>
<%@ taglib uri="/WEB-INF/ErrorTag.tld" prefix="error"%>
<head:Head
	author="Pomme" 
        import="calendar,textfield,error"
        jsFile="../script/checkValidData.js,../script/convertDataType.js,../script/dateCalendar.js,../script/Alert.js" 
	styleFile="../theme/defaultTheme.css,../theme/CFRLTheme.css,../theme/CFHDReportTheme.css" 
	title="List of Cases Opened X Day(s)">
</head:Head>  

  <body style="width:750px; margin-left:10px;">
        <%
                EproServletUtil servletUtil = new EproServletUtil(request);
                String country = request.getParameter("country");
                String p1 = request.getParameter("p1");
                String p2 = request.getParameter("p2");
                String p3 = request.getParameter("p3");
                String p4 = request.getParameter("p4");
                String day = request.getParameter("day");
                String from = request.getParameter("from");
                String to = request.getParameter("to");
                
                //initial data for query                
                if(day.equals(""))
                {
                        day = "0";
                }
                
                String caseType = "";
                String ShowCase = "";
                if(p1.equals("true"))
                {
                        p1 = "P1";
                        caseType = caseType + "'" + p1 + "'" + ",";
                        ShowCase = ShowCase + "User Question (P1)" + ",";
                }
                if(p2.equals("true"))
                {
                        p2 = "P2";
                        caseType = caseType + "'" + p2 + "'" + ",";
                        ShowCase = ShowCase + "Problem Report (P2)" + ",";
                }
                if(p3.equals("true"))
                {
                        p3 = "P3";
                        caseType = caseType + "'" + p3 + "'"+ ",";
                        ShowCase = ShowCase + "Change Request (P3)" + ",";
                }
                if(p4.equals("true"))
                {
                        p4 = "P4";
                        caseType = caseType + "'" + p4 + "'"+ ",";
                        ShowCase = ShowCase + "Service Request (P4)" + ",";
                }
                if(caseType.equals(""))
                {
                        caseType = null;
                        ShowCase = "";
                }
                else
                {
                        caseType = caseType.substring(0,caseType.length()-1);
                        ShowCase = ShowCase.substring(0,ShowCase.length()-1);
                }                
                              
                System.out.println("-----Country----- : " + country);
                System.out.println("-----P1----- : " + p1);
                System.out.println("-----P2----- : " + p2);
                System.out.println("-----P3----- : " + p3);
                System.out.println("-----day-----:" + day);
                System.out.println("-----from date-----:" + from);
                System.out.println("-----to date-----:" + to);
                System.out.println("-----Case Type-----:" + caseType);
                           
                //-----Query Data For Report-----
                CCaseReportManage ccaseManage = new CCaseReportManage();
                Vector progress = new Vector();
                Vector close = new Vector();
                SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
                SimpleDateFormat format2 = new SimpleDateFormat("dd/MM/yy", Locale.US);
                
                //Manage About Country
                CountryManage cManage = new CountryManage();
                String cName = "";
                if(!(country.equals("ALL")))
                {
                  Country cCountry = cManage.getCountry(country);
                  cName = cCountry.getCountryName();                
                }
                else
                {
                  cName = "ALL";
                }
                //In Progress Cases             
                try 
		{						
                        progress = ccaseManage.listCaseStillOpen(country,caseType,day,false,format.parse(from),format.parse(to));
		} 
		catch (ParseException e) 
		{	
			e.printStackTrace();
		}
                System.out.println("--------------------Progress-------------------- : " + progress);                  
                                
                // Close Cases
                try 
		{						
                        close = ccaseManage.listCaseStillOpen(country,caseType,day,true,format.parse(from),format.parse(to));
		} 
		catch (ParseException e) 
		{	
			e.printStackTrace();
		}
                System.out.println("--------------------Close-------------------- : " + close);  
                
                //Grand Total
                String pSize = "" + progress.size();
                String cSize = "" + close.size();
                
                int GrandTotal = 0;
                if ((progress.size() !=0) || (close.size() !=0))
                {
                        GrandTotal = progress.size() + close.size();
                }
                
        %>
        <%//------------------------Display Report------------------------%>
        <table width="740"  border="0" cellspacing="0" cellpadding="0" style="margin-left:3px;" bordercolor="green">
                <TR>
                        <TD align="center">
                                <IMG SRC= "../images/icon/toolbar/nBackToMenu.gif" alt="Back To Menu" onclick="backTomenu();" Style="cursor:hand"
                                onmouseover="Javascript: this.src='../images/icon/toolbar/oBackToMenu.gif' " 
                                onmouseout="Javascript: this.src='../images/icon/toolbar/nBackToMenu.gif' ">      
                        </TD>
                </TR>                
        </TABLE>
        
        <table width="740"  border="0" cellspacing="0" cellpadding="0" style="margin-left:3px;" bordercolor="green">
                <tr>
                        <td align="center">
                                <span class="Header"> E-Helpdesk</span>
                                <span class="Header">List of Cases Opened for More Than X Day(s)</span>
                        </td>
                </tr>
                <!-----------------------------------Title----------------------------------------------->
                <tr>
                        <td>      
                                <span class="viewCaseHeader"  style="text-align: right;"> Created Date : <%=currentDate%> </span>
                                <span class="viewCaseHeader"> Country : <%=cName%> </span>
                                <span class="viewCaseHeader"> Case Type  :   <%=ShowCase%></span>
                                <span class="viewCaseHeader"> Opened for More Than <%=day%> Days</span> 
                                <span class="viewCaseHeader"> Open Case Date From : <%=from%> To : <%=to%></span>
                        </td>
                </tr> 
                
                <!-----------------------------------Header Cloumn----------------------------------------------> 
                <tr>
                        <td >
				<div align="center" id="masterZone" style="overflow-x: hidden; overflow-y: hidden;">
					<table style="display: block;" cellspacing="0" cellpadding="0" align="left" width="735" bgcolor="darkorange" border="0" bordercolor="red">
        					<tr> 
                					<td bgcolor="darkorange" class="titleFont" style="text-align: left; color: white;"  width=<%=widthH1%>>Case ID</td>
							<td bgcolor="darkorange" class="titleFont" style="text-align: left; color: white;"  width=<%=widthH2%>>Subject</td>
                                                        <td bgcolor="darkorange" class="titleFont" style="text-align: left; color: white;"  width=<%=widthH3%>>Open Case Country</td>
							<td bgcolor="darkorange" class="titleFont" style="text-align: center; color: white;"  width=<%=widthH4%>>Open Case Date</td>
                                                        <td bgcolor="darkorange" class="titleFont" style="text-align: center; color: white;"  width=<%=widthH5%>>Opened for (Day/Hr/Min)</td>
							<td bgcolor="darkorange" class="titleFont" style="text-align: center; color: white;" width=<%=widthH6%>>Status</td>
							<td bgcolor="darkorange" class="titleFont" style="text-align: center; color: white;" width=<%=widthH7%>>Case Type</td>
						</tr>
					</table>
				</div>
                        </td>
                </tr>
   
   <!----------------------------------- /Header Cloumn----------------------------------------------> 
   
   <!-----------------------------------Progress Cases ----------------------------------------------->
   <tr>
    <td>
    	<DIV id="ReportMasterDiv">
	<FORM name="ReportMasterForm" style="border-color: red;border: 1px; ">    
        
        <!------------------------------------FOR-------------------------------------->   
        <table border="0" cellpadding="0"  cellspacing="0" bordercolor="purple" width="735">
                <tr>
                        <td colspan="7" class="TotalByCaseTyephaveline">
                        <span> In Progress Cases </span>
                        </td>                          
                </tr> 
                <tr>
                        <td>

                        <%   
                                if (progress.size()==0){
                        %>
                                                     
                            <tr >
                                    <td width=<%=width1%>>&nbsp; </td>
                                    <td  width=<%=width2%>>&nbsp; </td>
                                    <td width=<%=width3%>>&nbsp; </td>
                                    <td width=<%=width4%>>&nbsp; </td>
                                    <td width=<%=width5%> >&nbsp; </td>
                                    <td width=<%=width6%>>&nbsp; </td>
                                    <td width=<%=width7%>>&nbsp; </td>
                                </tr>
                        <%
                                }
                        %>
                        
                        <%
                                 if(progress.size() > 0)
                                 {
                        %>
                        
                        <%
                                        CfhdCaseHead pCase = new CfhdCaseHead();
                                         for(int i=0; i<=progress.size()-1; i++)
                                        {
                                        pCase = (CfhdCaseHead)progress.elementAt(i);
                        %>
                                <tr>
                                        <td class="resultFont" align="left" width=<%=width1%>><%=showData.CheckNull(pCase.getCaseId())%></td>
                                        <td class="resultFont" align="left" width=<%=width2%>><%=showData.CheckNull(pCase.getSubject())%></td>
                                        <td class="resultFont" align="left" width=<%=width3%>><%=showData.CheckNull(pCase.getCountry().getCountryName())%></td>
                                        <td class="resultFont" align="center" width=<%=width4%>><%=format2.format(pCase.getOpenCaseDate())%></td>
                                        <td class="resultFont" align="center" width=<%=width5%>><%=showData.CheckNull(pCase.getDuration())%></td>
                                        <td class="resultFont" align="center" width=<%=width6%>><%=showData.CheckNull(pCase.getStatusDesc(pCase.getCaseStatus()))%></td>
                                        <td class="resultFont" align="center" width=<%=width7%>><%=showData.CheckNull(pCase.getCaseType())%></td>                  
                                </tr>
                        <%           }//end for
                                 }//end if Vector > 0
                        %>                
                                <!-----------------------------------Total Progress -----------------------------------------------> 
                                <tr>                         
                                        <td colspan="3"style="border-top: 2px solid #FF8C00;  ">&nbsp;</td>
                                        <td colspan="4"style="border-top: 2px solid #FF8C00; text-align: right;">           
                                                <table border="0" align="right" width="80%"  cellpadding="0" cellspacing="0">
                                                        <tr >                                                                 
                                                                <td nowrap="nowrap" width=<%=width5%> class="TotalByCaseTyephaveline">Total </td>
                                                                <td nowrap="nowrap" width=<%=width6%>  class="TotalByCaseTyephaveline" style="text-align: right;"><%=pSize%></td>
                                                                <td nowrap="nowrap" width=<%=width7%> class="TotalByCaseTyephaveline"> Cases</td>
                                                        </tr>
                                                </table>   
                                        </td>  
                                </tr>
                                <!-----------------------------------End Total Progress ----------------------------------------------->                       
                        </td>                 
                </td>
        </tr> 
        
        <!-----------------------------------End Progress Cases ----------------------------------------------->
        
        <!-----------------------------------Close Cases ----------------------------------------------->
        
        <tr>       
                <!------------------------------------FOR-------------------------------------->   
        </tr>
                <tr>
                   <td colspan="7"  style="color: white; border-bottom : solid 2px black; font-weight: bold; font-size: 11px;  font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;">
                    <span>Black Line</span>
                  </td>
                
                </tr>
                 
                
                <tr>
                        <td colspan="7" class="TotalByCaseTyephaveline">
                        <span> Close Cases </span>
                        </td>  
                </tr> 
                <tr>
                        <td>
                        <%   
                                if (close.size()==0){
                        %>
                                                   
                            <tr >
                                    <td width=<%=width1%>>&nbsp; </td>
                                     <td  width=<%=width2%>>&nbsp;</td>
                                    <td width=<%=width3%>>&nbsp; </td>
                                    <td width=<%=width4%>>&nbsp; </td>
                                    <td width=<%=width5%>>&nbsp; </td>
                                    <td width=<%=width6%> >&nbsp; </td>
                                    <td width=<%=width7%>>&nbsp; </td>
                                </tr>
                        <%
                                }
                        %>
                        
                        <%
                                 if(close.size() > 0)
                                 {
                        %>
                        
                        <%
                                        CfhdCaseHead cCase = new CfhdCaseHead();
                                         for(int i=0; i<=close.size()-1; i++)
                                        {
                                        cCase = (CfhdCaseHead)close.elementAt(i);
                        %>
                                <tr>
                                        <td class="resultFont" align="left" width=<%=width1%>><%=showData.CheckNull(cCase.getCaseId())%></td>
                                        <td class="resultFont" align="left" width=<%=width2%>><%=showData.CheckNull(cCase.getSubject())%></td>
                                        <td class="resultFont" align="left" width=<%=width3%>><%=showData.CheckNull(cCase.getCountry().getCountryName())%></td>
                                        <td class="resultFont" align="center" width=<%=width4%>><%=format2.format(cCase.getOpenCaseDate())%></td>
                                        <td class="resultFont" align="center" width=<%=width5%>><%=showData.CheckNull(cCase.getDuration())%></td>
                                        <td class="resultFont" align="center" width=<%=width6%>><%=showData.CheckNull(cCase.getStatusDesc(cCase.getCaseStatus()))%></td>
                                        <td class="resultFont" align="center" width=<%=width7%>><%=showData.CheckNull(cCase.getCaseType())%></td>                  
                                </tr>
                        <%           }//end for
                                 }//end if Vector > 0
                        %>                  
                                
                                <!-----------------------------------Total Close -----------------------------------------------> 
                                  <tr>                               
                                        <td colspan="3"style="border-top: 2px solid #FF8C00;  ">&nbsp;</td>
                                        <td colspan="4"style="border-top: 2px solid #FF8C00; text-align: right;">               
                                                <table border="0" align="right" width="80%"  cellpadding="0" cellspacing="0">
                                                        <tr > 
                                                                <td nowrap="nowrap" width=<%=width5%> class="TotalByCaseTyephaveline">Total </td>
                                                                <td nowrap="nowrap" width=<%=width6%> class="TotalByCaseTyephaveline" style="text-align: right;"><%=cSize%></td>
                                                                <td nowrap="nowrap" width=<%=width7%> class="TotalByCaseTyephaveline"> Cases</td>
                                                        </tr>
                                                        <tr > 
                                                                <td nowrap="nowrap" width=<%=width5%> style="border-bottom: double  black; font-weight: bold; font-size: 11px;  font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;">Grand Total </td>
                                                                <td nowrap="nowrap" width=<%=width6%> style="border-bottom: double  black; text-align: right; font-weight: bold; font-size: 11px;  font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;"><%=GrandTotal%></td>
                                                                <td nowrap="nowrap" width=<%=width7%> style="border-bottom: double  black; font-weight: bold; font-size: 11px;  font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;"> Cases</td>
                                                        </tr>
                                                </table>   
                                        </td>  
                                </tr>
                                <!-----------------------------------End Total Close ----------------------------------------------->
                        </table>    
                        </td>
                </FORM>
                </div>
                </td>
        </tr> 
        <!-----------------------------------End Close Cases ----------------------------------------------->
        
</TABLE>
        
 <!-----------------------------------END  TABLE-----------------------------------------------> 
       
        <SCRIPT language="javascript">
                function backTomenu()
                {
                        <%=backClick%> ;
                }
        </SCRIPT>
  </body>
</html>
